# 1.打开浏览器
from time import sleep

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service(executable_path=r'E:\python\pythonshuju\chromedriver.exe')
driver = webdriver.Chrome(service=service)  #创建浏览器对象
# 2.输入访问地址（URL）
url = r"E:\pyCharm\PyCharm Pro 2024.1\PyCharmshuju\PycharmProjects\UI自动化测试\1\注册实例.html";
driver.get(url)
# 3.页面信息操作
# 1). 填写主页面的注册信息
# 用户名
driver.find_element(By.CSS_SELECTOR,"#user").send_keys("admin")
# 密码
driver.find_element(By.CSS_SELECTOR,"#password").send_keys("123456")
# 电话号码
driver.find_element(By.CSS_SELECTOR,"#tel").send_keys("13012345678")
# 电子邮件
driver.find_element(By.CSS_SELECTOR,"#email").send_keys("123@qq.com")


# 点击'注册A页面'链接
driver.find_element(By.PARTIAL_LINK_TEXT,"注册A").click()

# 4. 切换到新窗口（简单方法）
sleep(2)  # 等待新窗口打开
all_windows = driver.window_handles  # 获取所有窗口
driver.switch_to.window(all_windows[-1])  # 切换到最后一个窗口（通常是最新打开的）

# 用户名
driver.find_element(By.CSS_SELECTOR,"#userA").send_keys("1111")
# # 密码
driver.find_element(By.CSS_SELECTOR,"#passwordA").send_keys("123456")
# 电话号码
driver.find_element(By.CSS_SELECTOR,"#telA").send_keys("13012345678")
# 电子邮件
driver.find_element(By.CSS_SELECTOR,"#emailA").send_keys("123@qq.com")


# 4.关闭/退出浏览器
driver.quit()